<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #currentTime{
            font-size: 56px;
            font-weight: 800px;
            color: red;
            background-color: black;
        }
    </style>
</head>
<body>
    当前时间:<span id="currentTime"></span>
    <script>
        var currentTimeObj=document.getElementById("currentTime");
        //用定时器，每隔一秒钟对span进行赋值
        //1.箭头函数
         setInterval(()=>{ 
             var d=new Date();
             currentTimeObj.innerHTML=d.getHours()+":"+d.getMinutes()+":"+d.getSeconds();
         },1000)//1秒=1000毫秒
        //2.匿名函数
         setInterval(function(){ 
             var d=new Date();
             currentTimeObj.innerHTML=d.getHours()+":"+d.getMinutes()+":"+d.getSeconds();
         },1000);
        //3.不使用匿名函数
        function showTime(){
            var d=new Date();
            currentTimeObj.innerHTML=d.getHours()+":"+d.getMinutes()+":"+d.getSeconds();
        }
        setInterval(showTime,1000);
    </script>
</body>
</html>